package com.chaopei.day02;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Author Corday 天涯
 * @Date 2022/3/17 17:44
 * 线程池的使用
 */
public class MyPool {
    ExecutorService es;
    public MyPool(ExecutorService es){
        this.es = es;
    }
    public  void play(){
       Runnable rb=new Runnable() {
            @Override
            public void run() {
                String tname = Thread.currentThread().getName();
                System.out.println(tname+" 说话了");
                //ThreadPoolExecutor te =(ThreadPoolExecutor)es;
                //te.getActiveCount();
                //es.shutdown();
            }
        };
       es.submit(rb);
       //es.shutdownNow();
    }
}
//线程池测试
class  TestMyPool{
    public static void main(String[] args) {
        ExecutorService es = Executors.newFixedThreadPool(3);
        new MyPool(es).play();
        new MyPool(es).play();
        new MyPool(es).play();
        //关闭线程池
        es.shutdownNow();
    }
}